#!/usr/bin/env bash

CFLAGS="-c -g -Wall"
INCLS="-I$PROJ_DIR/src/include -I$LATOP/common/c/include -I$ORACLE_HOME/precomp/public -I$TUXDIR/include"

cmdir=$PROJ_DIR/src/cm
if [ "$PWD" != "$cmdir" ]
then
    echo "Error: current dir not $cmdir"
    exit
fi

src=$1.c
obj=$1.o
if [ ! -f "$src" ] 
then
    echo "Error: $src not exist"
    exit
fi

$CC $INCLS $CFLAGS -o $obj $src
if [ $? -eq 0 ]
then
    libcm=$PROJ_DIR/lib/libcm.a
    ar -crl $libcm $obj
    chmod 666 $libcm
    rm $obj
fi
